<?php

namespace App\Admin\Controllers;

use App\Models\Config;
use Encore\Admin\Form;
use Encore\Admin\Controllers\AdminController;

class ConfigsController extends AdminController
{
    protected $title = '商铺配置';

    protected function form()
    {
        $form = new Form(new Config());

        $form->tab('基本配置', function ($form) {
        	$form->text('name', '商铺名称');
	        $form->text('yysj', '商铺运营时间');
	         $form->text('desc', '介绍');
	        $form->mobile('phone', '公司手机')->rules('nullable|phone:CN,mobile');
	        $form->text('address', '公司地址');
	       
        })->tab('奖品上传', function ($form) {
           $form->image('image', '奖品图片上传')->uniqueName();
        
        })->tab('会员协议', function ($form) {
	        $form->simditor('user_agreement', '会员协议');
        });

        $this->formTools($form);
        $this->formSaved($form);
        $this->formFooter($form);

        return $form;
    }

    protected function formTools(Form $form)
    {
    	$form->tools(function (Form\Tools $tools) {
    		$tools->disableList();
    		$tools->disableView();
    		$tools->disableDelete();
	    });
    }

    protected function formFooter(Form $form)
    {
    	$form->footer(function (Form\Footer $footer) {
		    $footer->disableViewCheck();
		    $footer->disableCreatingCheck();
		    $footer->disableEditingCheck();
	    });
    }

	protected function formSaved(Form $form)
	{
		$form->saved(function () {
			admin_toastr('全局配置已更新', 'success');
			return redirect(route('admin.configs.edit', 1));
		});
	}
}
